package com.kee.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kee.server.mapper.*;
import com.kee.server.pojo.*;
import com.kee.server.service.IEmployeeService;
import com.kee.server.utils.AddStringUtil;
import com.kee.server.utils.AssertUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kee
 * @since 2021-03-24
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Resource
    private EmployeeMapper employeeMapper;

    @Resource
    private NationMapper nationMapper;

    @Resource
    private JobLevelMapper jobLevelMapper;

    @Resource
    private DepartmentMapper departmentMapper;

    @Resource
    private PoliticsStatusMapper politicsStatusMapper;

    @Resource
    private PositionMapper positionMapper;


    @Override
    public RespBean getMaxWorkID() {
        RespBean respBean = new RespBean();
        String wordID = AddStringUtil.addOne(employeeMapper.selectMaxWorkId());
        respBean.setObj(wordID);
        return respBean;
    }

    @Override
    public List<Position> getPositions() {
        return positionMapper.selectList(null);
    }

    @Override
    public List<Nation> getNations() {
        return nationMapper.selectList(null);
    }

    @Override
    public List<JobLevel> getJoblevels() {
        return jobLevelMapper.selectList(null);
    }

    @Override
    public List<PoliticsStatus> getPoliticsstatus() {
        return politicsStatusMapper.selectList(null);
    }

    @Override
    public void deleteEmp(Integer id) {
        //非空校验
        AssertUtil.isTrue(id == null, "待删除的记录不存在");
        Employee employee = employeeMapper.selectById(id);
        AssertUtil.isTrue(employee == null, "待删除记录不存在");

        AssertUtil.isTrue(employeeMapper.deleteById(id) < 1, "删除失败了");

    }

    @Override
    public void addEmp(Employee employee) {
        //非空校验
        AssertUtil.isTrue(employeeMapper.insert(employee) < 1, "添加失败了");


    }

    @Override
    public void updateEmp(Employee employee) {

//        System.out.println(employee.toString());
        Integer id = employee.getId();
        AssertUtil.isTrue(id == null || employeeMapper.selectById(id) == null, "待修改用户记录不存在");
        //非空校验
        AssertUtil.isTrue(employeeMapper.update(employee, null) < 1, "修改失败了");

    }

    @Override
    public List<Employee> employeeList() {
        return super.list();
    }
}
